/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightTransferSaveguard;
import com.sasis.dao.FlightTransferSaveguardDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightTransferSaveguardDaoiBatis extends BaseDaoiBATIS implements FlightTransferSaveguardDao {

    /**
     * @see com.sasis.dao.FlightTransferSaveguardDao#getFlightTransferSaveguards(com.sasis.model.FlightTransferSaveguard)
     */
    public List getFlightTransferSaveguards(final FlightTransferSaveguard flightTransferSaveguard) {
          return getSqlMapClientTemplate().queryForList("getFlightTransferSaveguards", flightTransferSaveguard);
    }

    /**
     * @see com.sasis.dao.FlightTransferSaveguardDao#getFlightTransferSaveguard(Integer id)
     */
    public FlightTransferSaveguard getFlightTransferSaveguard(Integer id) {
        FlightTransferSaveguard flightTransferSaveguard = (FlightTransferSaveguard) getSqlMapClientTemplate().queryForObject("getFlightTransferSaveguard", id);

        //if (flightTransferSaveguard == null) {
            //throw new ObjectRetrievalFailureException(FlightTransferSaveguard.class, id);
        //}

        return flightTransferSaveguard;
    }

    /**
     * @see com.sasis.dao.FlightTransferSaveguardDao#saveFlightTransferSaveguard(FlightTransferSaveguard flightTransferSaveguard)
     */    
    public int saveFlightTransferSaveguard(final FlightTransferSaveguard flightTransferSaveguard) {
        Integer id = flightTransferSaveguard.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightTransferSaveguard", flightTransferSaveguard);
        } else {
            getSqlMapClientTemplate().update("updateFlightTransferSaveguard", flightTransferSaveguard);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightTransferSaveguard.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightTransferSaveguardDao#removeFlightTransferSaveguard(Integer id)
     */
    public void removeFlightTransferSaveguard(FlightTransferSaveguard flightTransferSaveguard) {
        getSqlMapClientTemplate().update("deleteFlightTransferSaveguard",  flightTransferSaveguard);
    }
}
